home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 10 - 1994 / 10.10 Oct 94 / Prog Chal In Depth / RGBtoYUV Listing 1 next >
Encoding:
Text File  |  1994-09-13  |  1.3 KB  |  48 lines  |  [TEXT/R*ch]

  1. //RGBtoYUV
  2. //This is the RGBtoYUV routine before all the strange optimization was
  3. //applied.  The final version is in the following listing.
  4.  
  5. void RGBtoYUV(unsigned char *ra, unsigned char *ga,
  6.     unsigned char *ba, unsigned char *ya,
  7.     signed char *ua, signed char *va,
  8.     unsigned long numpix, void *pd)
  9. {
  10.     register signed32      index;
  11.     register signed32      i2;
  12.              unsigned32    i;
  13.     register unsigned32    hi, lo_rg, lo;
  14.     register unsigned char *yar = ya;
  15.     register signed char   *var = va;
  16.     register rgb_yuv_data  *p = pd;
  17.  
  18.     for(i=0; i<numpix; i++) {
  19.         /* Compute indexes */
  20.         index = ((*ra++)<<8)+(*ga++);
  21.         i2 = *ba++;
  22.  
  23.         /* Get high and low word from the RG arrays */
  24.         lo_rg = p->yuv_rg_l[index];
  25.         hi = p->yuv_rg_h[index];
  26.  
  27.         /* Add high and low words from the B arrays */
  28.         lo = lo_rg + p->yuv_b_l[i2];
  29.         hi += p->yuv_b_h[i2];
  30.  
  31.         /* Test for carry */
  32.         if (lo < lo_rg) {
  33.             /* there was a carry! */
  34.             hi++;
  35.  
  36.             /* Store results */
  37.             *ua++ = hi;
  38.             *yar++ = lo>>12L;
  39.             *var++ = hi>>21L;
  40.         } else {
  41.             /* Store results */
  42.             *ua++ = hi;
  43.             *yar++ = lo>>12L;
  44.             *var++ = hi>>21L;
  45.         }
  46.     }
  47. }
  48.